﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Reflection;
using System.Windows.Forms;
using HML.Design;

namespace HML
{
    /// <summary>
    /// 加载等待控件
    /// </summary>
    [Description("加载等待控件")]
    [DefaultProperty("Active")]
    [DefaultEvent("ActiveChanged")]
    [TypeConverter(typeof(PropertyOrderConverter))]
    [Designer(typeof(LoadWaitDesigner))]
    [ToolboxItem(true)]
    [ToolboxBitmap(typeof(LoadWait), "Controls.LoadWait.Resources.LoadWait.bmp")]
    public class LoadWait : MainThreadAnimationControl, ISkinObject
    {
        #region 主题

        private SkinObjectXmlMetadata skinObjectXmlMetadata = null;
        /// <summary>
        /// 主题对象在主题文件信息
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual SkinObjectXmlMetadata SkinObjectXmlMetadata
        {
            get
            {
                if (this.skinObjectXmlMetadata == null)
                    this.skinObjectXmlMetadata = new SkinObjectXmlMetadata(Assembly.GetAssembly(typeof(LoadWait)).GetName().Name, typeof(LoadWait).Name);

                return this.skinObjectXmlMetadata;
            }
        }

        private SkinController skinController = null;
        /// <summary>
        /// 主题控制器
        /// </summary>
        [Description("主题控制器")]
        [Category("杂项")]
        [PropertyOrder(-360)]
        [DefaultValue(null)]
        [RefreshProperties(RefreshProperties.All)]
        public virtual SkinController SkinController
        {
            get { return this.skinController; }
            set
            {
                if (this.skinController == value)
                    return;

                if (this.skinController != null)
                    this.skinController.RemoveSkinObject(this);

                this.skinController = value;

                if (this.skinController != null)
                    this.skinController.AddSkinObject(this);
            }
        }

        private SkinEnabledState skinEnabled= SkinEnabledState.Auto;
        /// <summary>
        /// 主题是否启用
        /// </summary>
        [Description("主题是否启用")]
        [Category("杂项")]
        [PropertyOrder(-300)]
        [DefaultValue(SkinEnabledState.Auto)]
        [RefreshProperties(RefreshProperties.All)]
        public virtual SkinEnabledState SkinEnabled
        {
            get { return this.skinEnabled; }
            set
            {
                if (this.skinEnabled == value)
                    return;

                this.skinEnabled = value;
                this.OnSkinChanged();
            }
        }

        private SkinStyle skinStyle = SkinStyle.Normal;
        /// <summary>
        /// 主题风格
        /// </summary>
        [Description("主题风格")]
        [Category("杂项")]
        [PropertyOrder(-260)]
        [DefaultValue(SkinStyle.Normal)]
        [RefreshProperties(RefreshProperties.All)]
        public virtual SkinStyle SkinStyle
        {
            get { return this.skinStyle; }
            set
            {
                if (this.skinStyle == value)
                    return;

                this.skinStyle = value;
                this.OnSkinChanged();
            }
        }

        private StyleAppearanceObject stateAppearance;
        /// <summary>
        /// 风格外观
        /// </summary>
        [Description("风格外观")]
        [Category("杂项")]
        [PropertyOrder(-200)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public StyleAppearanceObject StyleAppearance
        {
            get
            {
                if (this.stateAppearance == null)
                    this.stateAppearance = new StyleAppearanceObject(this, null);
                return this.stateAppearance;
            }
        }

        /// <summary>
        /// 主题已更改
        /// </summary>
        public virtual void OnSkinChanged()
        {
            SkinManager.SyncSkinValueToProperty(this);
            this.Invalidate();
        }

        private ISkinObject followSkinObject = null;
        /// <summary>
        /// 主题设置跟随指定主题对象（自己的设置不再生效，提供给代码使用）
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [Localizable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual ISkinObject FollowSkinObject
        {
            get { return this.followSkinObject; }
            set
            {
                if (this.followSkinObject == value)
                    return;

                this.followSkinObject = value;
                this.OnSkinChanged();
            }
        }

        public virtual bool GetSkinObjectSkinStateCore()
        {
            return SkinManager.GetSkinObjectSkinState(this.FollowSkinObject ?? this);
        }

        void ISkinObject.InitializeInvalidate()
        {
            this.InitializeBrushsAngle();
            this.Invalidate();
        }

        void ISkinObject.Invalidate()
        {
            this.Invalidate();
        }

        #endregion

        #region 新增事件

        private static readonly object EventActiveChanged = new object();
        /// <summary>
        /// 激活状态更改事件
        /// </summary>
        [Description("激活状态更改事件")]
        public event EventHandler ActiveChanged
        {
            add { Events.AddHandler(EventActiveChanged, value); }
            remove { Events.RemoveHandler(EventActiveChanged, value); }
        }

        #endregion

        #region 停用事件

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler PaddingChanged
        {
            add { base.PaddingChanged += value; }
            remove { base.PaddingChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler BackgroundImageChanged
        {
            add { base.BackgroundImageChanged += value; }
            remove { base.BackgroundImageChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler BackgroundImageLayoutChanged
        {
            add { base.BackgroundImageLayoutChanged += value; }
            remove { base.BackgroundImageLayoutChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler TabIndexChanged
        {
            add { base.TabIndexChanged += value; }
            remove { base.TabIndexChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler TabStopChanged
        {
            add { base.TabStopChanged += value; }
            remove { base.TabStopChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler TextChanged
        {
            add { base.TextChanged += value; }
            remove { base.TextChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler FontChanged
        {
            add { base.FontChanged += value; }
            remove { base.FontChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler RightToLeftChanged
        {
            add { base.RightToLeftChanged += value; }
            remove { base.RightToLeftChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler ImeModeChanged
        {
            add { base.ImeModeChanged += value; }
            remove { base.ImeModeChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler BackColorChanged
        {
            add { base.BackColorChanged += value; }
            remove { base.BackColorChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler ForeColorChanged
        {
            add { base.ForeColorChanged += value; }
            remove { base.ForeColorChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler Click
        {
            add { base.Click += value; }
            remove { base.Click -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler DoubleClick
        {
            add { base.DoubleClick += value; }
            remove { base.DoubleClick -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event MouseEventHandler MouseClick
        {
            add { base.MouseClick += value; }
            remove { base.MouseClick -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event MouseEventHandler MouseDoubleClick
        {
            add { base.MouseDoubleClick += value; }
            remove { base.MouseDoubleClick -= value; }
        }

        #endregion

        #region 新增属性

        private LoadWaitStylePattern stylePattern = LoadWaitStylePattern.Dot;
        /// <summary>
        /// 风格模式
        /// </summary>
        [Description("风格模式")]
        [Category("杂项")]
        [PropertyOrder(-198)]
        [DefaultValue(LoadWaitStylePattern.Dot)]
        public LoadWaitStylePattern StylePattern
        {
            get { return this.stylePattern; }
            set
            {
                if (this.stylePattern == value)
                    return;

                this.stylePattern = value;
                this.Size = this.GetControlAutoSize();
                this.Invalidate();
            }
        }

        private int brushDiameter = 7;
        /// <summary>
        /// 画笔直径大小
        /// </summary>
        [Description("画笔直径大小")]
        [Category("杂项")]
        [PropertyOrder(-194)]
        [DefaultValue(7)]
        public int BrushDiameter
        {
            get { return this.brushDiameter; }
            set
            {
                if (this.brushDiameter == value || value < 1)
                    return;

                this.brushDiameter = value;
                this.Size = this.GetControlAutoSize();
                this.Invalidate();
            }
        }

        private bool active = false;
        /// <summary>
        /// 是否已激活
        /// </summary>
        [Description("是否已激活")]
        [Category("杂项")]
        [PropertyOrder(-190)]
        [DefaultValue(false)]
        public bool Active
        {
            get { return this.active; }
            set
            {
                if (this.active == value)
                    return;

                this.active = value;
                this.brushStartIndex = 0;
                this.Invalidate();

                if (this.DesignMode)
                    return;

                if (this.Enabled && this.Visible && this.Active && this.Parent != null)
                {
                    MainThreadAnimationControl.AnimationStart(this);
                }
                else
                {
                    this.usedTime = 0;
                    MainThreadAnimationControl.AnimationStop(this);
                }

                this.OnActiveChanged(EventArgs.Empty);

            }
        }

        #endregion

        #region 重写属性

        protected override Size DefaultSize
        {
            get { return new Size(40, 40); }
        }

        protected override ImeMode DefaultImeMode
        {
            get { return ImeMode.Disable; }
        }

        #endregion

        #region 停用属性

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public new Padding Padding
        {
            get { return base.Padding; }
            set { base.Padding = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new int TabIndex
        {
            get { return base.TabIndex; }
            set { base.TabIndex = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public new bool TabStop
        {
            get { return base.TabStop; }
            set { base.TabStop = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override string Text
        {
            get { return base.Text; }
            set { base.Text = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public override Font Font
        {
            get { return base.Font; }
            set { base.Font = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public override RightToLeft RightToLeft
        {
            get { return base.RightToLeft; }
            set { base.RightToLeft = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new ImeMode ImeMode
        {
            get { return base.ImeMode; }
            set { base.ImeMode = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new Image BackgroundImage
        {
            get { return base.BackgroundImage; }
            set { base.BackgroundImage = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new ImageLayout BackgroundImageLayout
        {
            get { return base.BackgroundImageLayout; }
            set { base.BackgroundImageLayout = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override Color BackColor
        {
            get { return this.StyleAppearance.BackColor; }
            set { }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override Color ForeColor
        {
            get { return this.StyleAppearance.TextColor; }
            set { }
        }

        #endregion

        #region 字段

        /// <summary>
        /// 开始画笔索引
        /// </summary>
        private int brushStartIndex = 0;
        /// <summary>
        /// 画笔的数量
        /// </summary>
        private int brushCount = 8;

        /// <summary>
        /// 画笔角度
        /// </summary>
        private float[] brushAngles;

        /// <summary>
        /// 控件内边距
        /// </summary>
        private int contentPadding = 2;

        /// <summary>
        /// 动画已使用的时间
        /// </summary>
        private double usedTime = 0;
        /// <summary>
        /// 动画时间间隔(毫秒)
        /// </summary>
        private int interval = 100;

        #endregion

        public LoadWait()
        {
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            this.SetStyle(ControlStyles.ResizeRedraw, true);
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.SetStyle(ControlStyles.StandardClick, false);
            this.SetStyle(ControlStyles.StandardDoubleClick, false);
            this.SetStyle(ControlStyles.Selectable, false);

            this.TabStop = false;
            this.InitializeBrushsAngle();
            this.OnSkinChanged();

        }

        #region 重写

        protected override void OnScaleDpiChangedInitialize()
        {
            this.Size = this.GetControlAutoSize();
            this.InitializeBrushsAngle();
            this.Invalidate();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Graphics g = e.Graphics;
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.CompositingQuality = CompositingQuality.HighQuality;

            int scale_brush_diameter = (int)(Math.Ceiling(this.BrushDiameter * this.ScaleDpi) / 2f) * 2;
            PointF center_point = new PointF(this.ClientRectangle.X + this.ClientRectangle.Width / 2f, this.ClientRectangle.Y + this.ClientRectangle.Height / 2f);


            Color tmp = this.StyleAppearance.BrushColor;

            Color[] brushsColorArr = new Color[this.brushCount];

            byte transparent = 0;//颜色透明度
            byte transparentIncrement = (byte)(byte.MaxValue / this.brushCount);//颜色透明度增量
            for (int i = 0; i < this.brushCount; i++)
            {
                Color color = tmp;
                if (i > 0)
                {
                    transparent += transparentIncrement;
                    transparent = Math.Min(transparent, byte.MaxValue);
                    color = Color.FromArgb(transparent, Math.Min(tmp.R, byte.MaxValue), Math.Min(tmp.G, byte.MaxValue), Math.Min(tmp.B, byte.MaxValue));
                }
                brushsColorArr[i] = color;
            }

            if (this.StylePattern == LoadWaitStylePattern.Line)
            {
                int current_index = this.brushStartIndex;
                Pen line_pen = new Pen(Color.Transparent, scale_brush_diameter) { StartCap = LineCap.Round, EndCap = LineCap.Round };
                for (int i = 0; i < this.brushCount; i++)
                {
                    current_index = current_index % this.brushCount;
                    PointF point_start = ControlHelper.CalculatePointForAngle(center_point, scale_brush_diameter * 1.8f, (float)this.brushAngles[current_index]);
                    PointF point_end = ControlHelper.CalculatePointForAngle(center_point, scale_brush_diameter * 3.8f, (float)this.brushAngles[current_index]);
                    line_pen.Color = brushsColorArr[i];

                    g.DrawLine(line_pen, point_start, point_end);

                    current_index++;
                }
                line_pen.Dispose();
            }
            else if (this.StylePattern == LoadWaitStylePattern.Dot)
            {
                int current_index = this.brushStartIndex;
                SolidBrush dot_sb = new SolidBrush(Color.Transparent);
                for (int i = 0; i < this.brushCount; i++)
                {
                    current_index = current_index % this.brushCount;
                    PointF point_start = ControlHelper.CalculatePointForAngle(center_point, scale_brush_diameter * 1.6f, (float)this.brushAngles[current_index]);
                    dot_sb.Color = brushsColorArr[i];

                    g.FillEllipse(dot_sb, point_start.X - scale_brush_diameter / 2, point_start.Y - scale_brush_diameter / 2, scale_brush_diameter, scale_brush_diameter);

                    current_index++;
                }
                dot_sb.Dispose();
            }

        }

        protected override void OnEnabledChanged(EventArgs e)
        {
            base.OnEnabledChanged(e);

            if (this.DesignMode)
                return;

            if (this.Visible && this.Enabled && this.Active && this.Parent != null)
            {
                MainThreadAnimationControl.AnimationStart(this);
            }
            else
            {
                this.usedTime = 0;
                MainThreadAnimationControl.AnimationStop(this);
            }
        }

        protected override void OnVisibleChanged(EventArgs e)
        {
            base.OnVisibleChanged(e);

            if (this.DesignMode)
                return;

            if (this.Visible && this.Enabled && this.Active && this.Parent != null)
            {
                MainThreadAnimationControl.AnimationStart(this);
            }
            else
            {
                this.usedTime = 0;
                MainThreadAnimationControl.AnimationStop(this);
            }
        }

        protected override void OnParentChanged(EventArgs e)
        {
            base.OnParentChanged(e);

            if (this.DesignMode)
                return;

            if (this.Visible && this.Enabled && this.Active && this.Parent != null)
            {
                MainThreadAnimationControl.AnimationStart(this);
            }
            else
            {
                this.usedTime = 0;
                MainThreadAnimationControl.AnimationStop(this);
            }
        }

        protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
        {
            Size tmp = this.GetControlAutoSize();
            base.SetBoundsCore(x, y, tmp.Width, tmp.Height, specified);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                this.usedTime = 0;
                MainThreadAnimationControl.AnimationStop(this);
            }
            base.Dispose(disposing);
        }

        /// <summary>
        /// 动画控件动画中要处理的内容(不能时耗时操作)
        /// </summary>
        /// <param name="interval">动画定时器间隔时间</param>
        protected override void Animationing(int interval)
        {
            this.usedTime += interval;
            if (this.usedTime > this.interval)
            {
                this.usedTime = 0;

                this.brushStartIndex += 1;
                if (this.brushStartIndex > this.brushCount - 1)
                {
                    this.brushStartIndex -= this.brushCount - 1;
                }

                this.Invalidate();
            }
        }

        #endregion

        #region 虚方法

        protected virtual void OnActiveChanged(EventArgs e)
        {
            EventHandler handler = Events[EventActiveChanged] as EventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        #endregion

        #region 私有方法

        /// <summary>
        /// 初始化选项角度
        /// </summary>
        /// <returns></returns>
        private void InitializeBrushsAngle()
        {
            float[] brushsAngle_tmp = new float[this.brushCount];
            float avgAngle = 360f / this.brushCount;
            for (int i = 0; i < this.brushCount; i++)
            {
                brushsAngle_tmp[i] = (i + 1) * avgAngle;
            }
            this.brushAngles = brushsAngle_tmp;
        }

        /// <summary>
        /// 根据画笔大小计算控件高度
        /// </summary>
        /// <returns></returns>
        private Size GetControlAutoSize()
        {
            int scale_contentPadding = (int)Math.Ceiling(this.contentPadding * this.ScaleDpi);
            int scale_brush_diameter = (int)(Math.Ceiling(this.BrushDiameter * this.ScaleDpi) / 2f) * 2;
            if (this.StylePattern == LoadWaitStylePattern.Line)
            {
                PointF point_left = ControlHelper.CalculatePointForAngle(new PointF(0, 0), scale_brush_diameter * 3.8f, 180);
                PointF point_right = ControlHelper.CalculatePointForAngle(new PointF(0, 0), scale_brush_diameter * 3.8f, 360);

                int width = (int)(point_right.X - point_left.X + scale_brush_diameter + scale_contentPadding * 2);
                return new Size(width, width);
            }
            else
            {
                PointF point_left = ControlHelper.CalculatePointForAngle(new PointF(0, 0), scale_brush_diameter * 1.6f, 180);
                PointF point_right = ControlHelper.CalculatePointForAngle(new PointF(0, 0), scale_brush_diameter * 1.6f, 360);

                int width = (int)(point_right.X - point_left.X + scale_brush_diameter + scale_contentPadding * 2);
                return new Size(width, width);
            }
        }

        #endregion

        #region 外观

        public class StyleAppearanceObject : AppearanceObjectBase
        {
            internal StyleAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

            #region 属性

            private Color skinBackColor = Color.Empty;
            private readonly Color defaultBackColor = SystemColors.Control;
            private Color backColor = Color.Empty;
            /// <summary>
            /// 背景颜色
            /// </summary>
            [Description("背景颜色")]
            [PropertyOrder(-195)]
            [SkinProperty(true, true)]
            public Color BackColor
            {
                get
                {
                    if (this.owner.GetSkinObjectSkinStateCore() && this.skinBackColor != Color.Empty)
                    {
                        return this.skinBackColor;
                    }

                    if (this.backColor != Color.Empty)
                    {
                        return this.backColor;
                    }

                    if (((Control)this.owner).Parent != null)
                    {
                        return ((Control)this.owner).Parent.BackColor;
                    }

                    return this.defaultBackColor;
                }
                set
                {
                    if (this.backColor == value)
                        return;

                    this.backColor = value;
                    this.Invalidate();
                }
            }
            private bool ShouldSerializeBackColor()
            {
                return this.backColor != Color.Empty;
            }
            private void ResetBackColor()
            {
                this.backColor = Color.Empty;
                this.Invalidate();
            }

            private Color skinTextColor = Color.Empty;
            private readonly Color defaultTextColor = SystemColors.ControlText;
            private Color textColor = Color.Empty;
            /// <summary>
            /// 文本颜色
            /// </summary>
            [Description("文本颜色")]
            [PropertyOrder(-193)]
            [SkinProperty(true, true)]
            public Color TextColor
            {
                get
                {
                    if (this.owner.GetSkinObjectSkinStateCore() && this.skinTextColor != Color.Empty)
                    {
                        return this.skinTextColor;
                    }

                    if (this.textColor != Color.Empty)
                    {
                        return this.textColor;
                    }

                    if (((Control)this.owner).Parent != null)
                    {
                        return ((Control)this.owner).Parent.ForeColor;
                    }

                    return this.defaultTextColor;
                }
                set
                {
                    if (this.textColor == value)
                        return;

                    this.textColor = value;
                    this.Invalidate();
                }
            }
            private bool ShouldSerializeTextColor()
            {
                return this.textColor != Color.Empty;
            }
            private void ResetTextColor()
            {
                this.textColor = Color.Empty;
                this.Invalidate();
            }

            private Color skinBrushColor = Color.Empty;
            private readonly Color defaultBrushColor = SystemColors.ActiveCaption;
            private Color brushColor = Color.Empty;
            /// <summary>
            /// 画笔颜色
            /// </summary>
            [Description("画笔颜色")]
            [PropertyOrder(-192)]
            [SkinProperty(true, false)]
            public Color BrushColor
            {
                get
                {
                    if (this.owner.GetSkinObjectSkinStateCore())
                    {
                        return this.skinBrushColor;
                    }

                    if (this.brushColor != Color.Empty)
                    {
                        return this.brushColor;
                    }

                    return this.defaultBrushColor;
                }
                set
                {
                    if (this.brushColor == value)
                        return;

                    this.brushColor = value;
                    this.Invalidate();
                }
            }
            private bool ShouldSerializeBrushColor()
            {
                return this.brushColor != Color.Empty;
            }
            private void ResetBrushColor()
            {
                this.brushColor = Color.Empty;
                this.Invalidate();
            }

            #endregion

        }

        #endregion

    }


}
